#include "PlaylistMainWindow.h"

#include "IF_MediaEngineInterface.h"
#include "MediaListModel.h"
#include "PlaylistAutomation.h"
#include "PlaylistFunctionFactory.h"

#include "PlaylistGuiFactory.h"
#include "MediaPlayBar.h"
#include "ActionListController.h"
#include "ActionListView.h"
#include "volumeslider.h"
#include "ExponentialFader.h"

/* insert here a valid path of a media file */
#define  MEDIA_FILE_PATH_1  QString("C:/Users/Public/Music/Sample Music/Sleep Away.mp3")
#define  MEDIA_FILE_PATH_2  QString("C:/Users/Public/Music/Sample Music/Kalimba.mp3")
#define  MEDIA_FILE_PATH_3  QString("C:/Users/Public/Music/Sample Music/Maid with the Flaxen Hair.mp3")

/**
 * build a minimal playlist Gui with relative engine to
 * show how it works (and to show that actually works!).
 *
 * This module works as a factory
 */
MainWindow::MainWindow(QWidget *parent)
   : QMainWindow(parent)
{
   PlaylistFunctionFactory *functionFactory = new PlaylistFunctionFactory( this);
   PlaylistGuiFactory *guiFactory = new PlaylistGuiFactory( this);

   MediaListModel *mediaModel = functionFactory->buildModel();
   IF_MediaEngineInterface *mediaEngine = functionFactory->buildEngine( mediaModel);

   MediaPlayBar *playbar = guiFactory->buildPlayBar( mediaEngine, this);
   ActionListController *actionController = new ActionListController( *mediaModel, this);
   ActionListView *playlistView = guiFactory->buildPlaylistView( playbar, mediaModel,
                                                                 actionController, this);
   setCentralWidget( playlistView);

   Fader *fader = new ExponentialFader( this);
   PlaylistAutomation *automation = functionFactory->buildAutomation( mediaModel, mediaEngine,
                                                                      actionController, fader);

   connect( actionController, SIGNAL(activeRowChanged(int)),
            automation, SLOT(activateByRowNumer(int)) );

   /* insert item. Normally done from GUI */
   mediaModel->addMediaFile( MEDIA_FILE_PATH_1);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_2);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_3);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_1);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_2);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_3);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_1);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_2);
   mediaModel->addMediaFile( MEDIA_FILE_PATH_3);
}

MainWindow::~MainWindow()
{
}


